﻿@{
    ViewBag.Title = "产品故障问题申报";
    Layout = "~/Views/Shared/WeixinApp/_Form.cshtml";
}

<header class='header'>
    
</header>
<div id="form">
    <form id="form1">
        <div class="weui-cells_form" style="background-color: #fff;">
            <div class="weui-cell ">
                <div class="weui-cell__hd">
                    <label class="weui-label">问题设备:</label>
                </div>
                <div class="weui-cell__bd">
                    <input type="text" class="weui-input" id="T_ProductName" name="T_ProductName" placeholder="" />
                </div>
                <div class="weui-cell__ft"><i class="weui-icon-warn"></i></div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">联系人：</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" id="T_Linkman" name="T_Linkman" maxlength="18" placeholder="">
                </div>
                <div class="weui-cell__ft"><i class="weui-icon-warn"></i></div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">联系电话：</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="tel" id="T_Mobile" name="T_Mobile" required pattern="^\d{11}$" maxlength="11" >
                </div>
                <div class="weui-cell__ft"><i class="weui-icon-warn"></i></div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd">
                    <label class="weui-label">QQ/微信：</label>
                </div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="tel" id="T_QQ" name="T_QQ" >
                </div>
                <div class="weui-cell__ft"><i class="weui-icon-warn"></i></div>
            </div>
            <div class="weui-cells__title">问题描述（必填）</div>
            <div class="weui-cells">
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <textarea id="T_Description" name="T_Description" class="weui-textarea" placeholder="请输入问题描述" rows="3"></textarea>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <div class="weui-uploader">
                            <div class="weui-uploader__hd">
                                <p class="weui-uploader__title">上传图片（软件错误界面，设备故障照片等）</p>
                                <div class="weui-uploader__info" id="uploader_count" data-total="3" data-val="0">0/3</div>
                            </div>
                            <div class="weui-uploader__bd">
                                <ul class="weui-uploader__files" id="uploader_files"></ul>
                                <div class="weui-uploader__input-box">
                                    <input class="weui-uploader__input" id="uploader_input" type="file" accept="image/*" multiple>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>

        <div class="weui-btn-area">
            <input type="hidden" id="T_SerialNo" name="T_SerialNo" />
            <input type="hidden" id="T_CustomerId" name="T_CustomerId" />
            <a id="formSubmitBtn" href="javascript:" class="weui-btn weui-btn_primary">提交</a>
        </div>
    </form>
</div>
<div id="gallery" class="weui-gallery">
    <span id="galleryImg" class="weui-gallery__img" style="background-image: url(xxx);"></span>
    <div class="weui-gallery__opr">
        <a href="javascript:" class="weui-gallery__del">
            <i class="weui-icon-delete weui-icon_gallery-delete"></i>
        </a>
    </div>
</div>
<div class="weui-footer">
    <p class="weui-footer__text"></p>
</div>

<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="~/Content/weui/js/jquery-weui.min.js"></script>
<script src="~/Content/weui/js/weui.min.js"></script>
<script src="~/Content/weui/js/weui.expand.js?t=v190702"></script>
<script>
    var detailData = [];
    var openid = $.cookie('openid');
    var customerId = $.getQueryString("customerId");
    var keyValue = $.getQueryString("keyValue");
    var deviceList = [];
    $(document).ready(function () {
        $("#T_CustomerId").val(customerId);
        getDevice();
    });

    function getDevice() {
        var req = {
            keyValue: customerId,
            keyword: ""
        };
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/ProductManage/ProductDevice/GetListJson",
            data: req,
            success: function (data){
                console.log(data.data);
                var list = [];
                for (var x in data.data) {
                    var item = { "title": data.data[x].T_ProductName, "value": data.data[x].T_SerialNo };
                    //alert(JSON.stringify(item));
                    list.push(item);
                }
                deviceList = list;
            }
        });
    }
    $("#T_ProductName").on("click", function () {
        $(this).select({
            title: "选择设备信息",
            items: deviceList
        });
        return false;
    });
    $("#formSubmitBtn").on('click', function () {

        var mobile = $("#T_Mobile").val();
        if (!mobile || !/1[3|4|5|7|8]\d{9}/.test(mobile)) {
            $.toptip('请输入正确手机号');
            return;
        }
        if (!$("#T_Linkman").val()) {
            $.toptip('请输入姓名');
            return;
        }
        if (!$("#T_ProductName").val()) {
            $.toptip('请选择问题设备');
            return;
        }
        if (!$("#T_Description").val()) {
            $.toptip('请选择问题描述内容');
            return;
        }
        $("#T_SerialNo").val($("#T_ProductName").attr("data-values"))
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/WeixinApp/WorkOrder/SubmitForm",
            data: $('#form1').serialize(),
            beforeSend: function (XMLHttpRequest) {
                $.showLoading("正在提交");
            },
            success: function (data) {
                $.hideLoading();
                if (data.state == "success") {
                    $.alert(data.message, "提示！", function () {
                        $.redirectTo("Index", customerId, "");
                    });
                } else {
                    $.alert("" + data.message, "警告！");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.hideLoading();
                $.alert("提交出错，请重试！", "警告！");
            }
        });
        return false;
    });

</script>

